#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5,M=2005;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int n,q,a[N],pre[N];
vector<pair<int,int> > que[N];

struct Frac{
	int x,y;
	bool friend operator<(const Frac a,const Frac b){
		return (__int128)a.x*b.y<(__int128)b.x*a.y;
	}
	bool friend operator>(const Frac a,const Frac b){
		return (__int128)a.x*b.y>(__int128)b.x*a.y;
	}
}sum[M][M];

Frac ans[N];

signed main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),pre[i]=pre[i-1]+a[i];
	q=read();
	if(n<=2000){
		for(int len=1;len<=n;len++){
			for(int l=1;l+len-1<=n;l++){
				int r=l+len-1;
				sum[l][r]={(pre[r]-pre[l-1])*(pre[r]-pre[l-1]),len};
				if(len>1){
					sum[l][r]=max(sum[l][r],sum[l+1][r]);
					sum[l][r]=max(sum[l][r],sum[l][r-1]);
				}
			}
		}
		while(q--){
			int l=read(),r=read();
			Frac mx=sum[l][r];
			int gd=__gcd(mx.x,mx.y);
			printf("%lld %lld\n",mx.x/gd,mx.y/gd);		
		}
	}
	else if(q==1){
		int lim=500000000/n;
		while(q--){
			int l=read(),r=read();
			Frac mx={0,1};
			for(int i=l;i<=r;i++){
				int res=0,len=0;
				for(int j=i;j<=min(r,i+lim);j++){
					res+=a[j];
					len++;
					mx=max(mx,(Frac){res*res,len});
				}
			}
			int gd=__gcd(mx.x,mx.y);
			printf("%lld %lld\n",mx.x/gd,mx.y/gd);
		}
	}
	else{
		for(int i=1;i<=q;i++){
			int l=read(),r=read();
			que[l].emplace_back(r,i);
		}
		for(int i=1;i<=n;i++) sort(que[i].begin(),que[i].end());
		for(int i=1;i<=n;i++){
			if(que[i].empty()) continue;
			int pos=0,res=0,len=0;
			Frac mx={0,1};
			for(int j=i;j<=min(i+1000,n);j++){
				res+=a[j],len++;
				mx=max(mx,(Frac){res*res,len});
				while(pos<que[i].size()&&que[i][pos].first==j) ans[que[i][pos].second]=mx,pos++;
				if(pos==que[i].size()) break;
			}
			while(pos<que[i].size()) ans[que[i][pos].second]=mx,pos++;
		}
		for(int i=1;i<=q;i++){
			int gd=__gcd(ans[i].x,ans[i].y);
			printf("%lld %lld\n",ans[i].x/gd,ans[i].y/gd);
		}
	}
	return 0;
}